<?php defined('InNcPHP') or exit('Access Invalid!');?>

<link rel="stylesheet" type="text/css" href="./resource/css/diyUpload/css/webuploader.css">
<link rel="stylesheet" href="./resource/css/diyUpload/css/demo.css">

<style>
    #img-content { margin: 10px 20px;font-size: 0; }
    #img-content li {
        display: inline-block;
        position: relative;
        height: 100px;
        width: 150px;
        border: 2px dashed #804c2e;
        margin: 0 5px 5px 0;
    }
    .img-list { width: 100%;height: 100%;vertical-align: middle; }
    .img-del {
        position: absolute;
        width: 20px;
        height: 20px;
        background-color: red;
        border-bottom-left-radius: 50%;
        text-align: center;
        font-size: 14px;
        color: #fff;
        top: 0;
        right: 0;
        cursor: pointer;
    }
    .img-del:hover {  background-color: rgba(255,0,0,0.7); }
    .show { display: block; }
    .hide { display: none; }

</style>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3>票型：</h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <?php echo $output['sub_link'];?>


    <form id="ticket_form" method="post" enctype="multipart/form-data">
        <input type="hidden" name="form_submit" value="ok" />
        <table class="table tb-type2 nobdb">
            <tfoot>
            <!-- 房型名称 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">票型名称:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="all_spec_name" class="txt" value="<?php echo $output['spec_info']['spec_name'] ?>"></td>
                <td class="vatop tips"><?php echo $lang['ticket_add_title_notice'];?></td>
            </tr>
            <!-- 标签 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">标签:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="all_label" class="txt" value="<?php echo $output['spec_info']['label'] ?>"></td>
                <td class="vatop tips"><?php echo $lang['ticket_add_title_notice'];?></td>
            </tr>
           <!-- 库存 房间数量 -->
           <!-- <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">库存:</label>
                </td>
            </tr>-->
           <!-- <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="all_stock" class="txt" value="<?php /*echo $output['spec_info']['stock'] */?>"></td>
                <td class="vatop tips"><?php /*echo $lang['ticket_add_title_notice'];*/?></td>
            </tr>-->
            <!-- 房型封面图片 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">票型封面图:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <span class="type-file-show">
                        <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
                        <div class="type-file-preview" style="display: none;">
                            <img id="view_img" src="<?php echo $output['spec_info']['surface_img']; ?>" style="max-height: 100px;max-width: 100px;">
                        </div>
                    </span>
                    <span class="type-file-box">
                        <input type='text' name='textfield' id='textfield' class='type-file-text' />
                        <input type='button' name='button' id='button' value='' class='type-file-button' />
                        <input name="thumb" type="file" class="type-file-file" id="image" size="30" hidefocus="true" />
                    </span>
                </td>
                <td class="vatop tips"><?php echo $lang['ticket_add_image_notice'];?></td>
            </tr>
            <!-- 上否上架 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">是否上架:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform onoff">
                    <label for="recommend1" class="cb-enable <?php echo $output['spec_info']['is_show'] == 1 ? 'selected' : ''; ?>"><span><?php echo $lang['nc_yes'];?></span></label>
                    <label for="recommend0" class="cb-disable <?php echo $output['spec_info']['is_show'] == 0 ? 'selected' : ''; ?>"><span><?php echo $lang['nc_no'];?></span></label>
                    <input id="recommend1" name="is_show" <?php echo $output['spec_info']['is_show'] == 1 ? 'checked' : ''; ?>  value="1" type="radio">
                    <input id="recommend0" name="is_show" <?php echo $output['spec_info']['is_show'] == 0 ? 'checked' : ''; ?>  value="0" type="radio">
                </td>
                <td class="vatop tips"></td>
            </tr>
            <!-- 票券类型价格-->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">固定价格:</label>
                </td>
                <td class="vatop tips">请设置票券类型的固定价格,（若需设置每日的单独价格，请提交保存后至列表中设置）</td>
            </tr>
            <!-- SKU设置 -->
            <?php foreach ($output['types'] as $type): ?>
                <?php foreach ($output['spec_info']['sku'] as $sku): ?>
                    <?php if ($sku['type_id'] == $type['type_id']): ?>
                        <tr class="noborder type_fix">
                            <td colspan="2" class="required">
                                <label><input type="checkbox"  name="types[<?php echo $type['type_id'];?>]" checked onclick="changeUse($(this));"><?php echo $type['type_name'];?></label>
                            </td>
                        </tr>
                        <tr class="type_fix inputs">
                            <td colspan="2">
                                <?php echo $lang['ticket_index_store']; ?>：<input type="text"  name="store<?php echo $type['type_id'];?>" value="<?php echo $sku['sku_store']; ?>">
                                <?php echo $lang['ticket_index_price']; ?>：<input type="text" <?php if($output['admin_info']['merchant_id']>0){ ?> readonly="true" <?php } ?>  name="price<?php echo $type['type_id'];?>" value="<?php echo $sku['sku_price']; ?>">
                                协议价：<input type="text" <?php if($output['admin_info']['merchant_id']>0){ ?> readonly="true" <?php } ?>  name="cost_price<?php  echo $type['type_id']; ?>" value="<?php echo $sku['sku_cost_price']; ?>">
                            </td>
                        </tr>
                        <?php continue 2; ?>
                    <?php endif; ?>
                <?php endforeach; ?>
                <tr class="noborder type_fix <?php echo $output['spec_info']['tk_type']?'hide':''; ?>">
                    <td colspan="3" class="required">
                        <label><input type="checkbox" name="types[<?php echo $type['type_id'];?>]"  onclick="changeUse($(this));"><?php echo $type['type_name'];?></label>
                    </td>
                </tr>
                <tr class="type_fix inputs">
                    <td colspan="3">
                        <?php echo $lang['ticket_index_store']; ?>：<input type="text" name="store<?php echo $type['type_id'];?>">
                        <?php echo $lang['ticket_index_price']; ?>：<input type="text" <?php if($output['admin_info']['merchant_id']>0){ ?> readonly="true" <?php } ?>  name="price<?php echo $type['type_id'];?>">
                        协议价：<input type="text"  <?php if($output['admin_info']['merchant_id']>0){ ?> readonly="true" <?php } ?> name="cost_price<?php  echo $type['type_id']; ?>">
                    </td>
                </tr>
            <?php endforeach; ?>

            <!-- 门票详情 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['ticket_add_detail'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td colspan="2" class="vatop rowform">
                    <textarea id="content" name="content" style="width:70%;height: 400px;"><?php echo $output['spec_info']['detail']; ?></textarea>
                </td>
            </tr>
            <!-- 购买须知 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['ticket_add_tips'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td colspan="2" class="vatop rowform">
                    <textarea id="content1" name="content1" style="width:70%;height: 400px;"><?php echo $output['spec_info']['tips']; ?></textarea>
                </td>
            </tr>
            <table class="table tb-type2" id="prompt">
                <tbody>
                <tr class="space odd">
                    <th class="nobg" colspan="12"><div class="title"><h5>景点图册</h5><span class="arrow"></span></div></th>
                </tr>
                <tr>
                    <td>
                        <ul>
                            <li>点击图片上传，再点击右下角开始上传按钮</li>
                        </ul></td>
                </tr>
                </tbody>
            </table>
            <!--  图片列表  -->
            <ul id="img-content">
                <?php foreach ($output['images'] as $img): ?>
                    <li>
                        <img class="img-list" src="<?php echo $img['img_path']; ?>" alt="IMG">
                        <span class="img-del" data-img_id="<?php echo $img['img_id']; ?>">X</span>
                    </li>
                <?php endforeach; ?>
            </ul>

            <!--  上传插件  -->
            <div id="uploader">
                <div class="queueList">
                    <div id="dndArea" class="placeholder">
                        <div id="filePicker"></div>
                        <p>高版本浏览器可将照片拖到这里，单次最多可选30张</p>
                    </div>
                </div>
                <div class="statusBar" style="display:none;">
                    <div class="progress">
                        <span class="text">0%</span>
                        <span class="percentage"></span>
                    </div><div class="info"></div>
                    <div class="btns">
                        <div id="filePicker2"></div><div class="uploadBtn">开始上传</div>
                    </div>
                </div>
            </div>
<!-- 提交 -->
            <tr class="tfoot">
                <td colspan="2" >
                    <a href="JavaScript:void(0);" class="btn" id="submitBtn">
                        <span><?php echo $lang['nc_submit'];?></span>
                    </a>
                </td>
            </tr>
            </tfoot>
        </table>

    </form>

</div>
<script type="text/javascript" SRC="./resource/kindeditor/kindeditor-min.js"></script>
<script>

    var UPLOAD_URL = 'index.php?act=ticket&op=ajax_imgs&spec_id=<?php echo $output['spec_info']['spec_id']; ?>';
    $(document).on('click', '.img-del', function () {
        var _this = $(this);
        var img_id = _this.data('img_id');
        layer.confirm('<?php echo $lang['ticket_day_confirm_del']; ?> ', {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            $.post('index.php?act=common&op=delimg', {img_id: img_id}, function (data) {
                if (data.res) {
                    _this.parent().remove();
                    layer.alert('<?php echo $lang['ticket_day_del_succ']; ?>');
                } else {
                    layer.alert('<?php echo $lang['ticket_day_del_fail']; ?>');
                }
            }, 'json');
        });

    });

    //门票类型改变选中状态（儿童票、成人票等）
    function changeUse(obj) {
        var td = obj.parent().parent().parent().next();
        if (obj.is(':checked') == false) {
            td.hide().find('input').val('');
        } else {
            td.show();
        }
    }
    //实例化富文本编辑器
    KindEditor.ready(function(K){
        K.create('textarea[name="content"]', {
            themeType: 'simple',
            resizeType: 1,
            uploadJson: './resource/kindeditor/php/upload_json.php',
            fileManagerJson: './resource/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function(){this.sync();}
        });
        K.create('textarea[name="content1"]', {
            themeType: 'simple',
            resizeType: 1,
            uploadJson: './resource/kindeditor/php/upload_json.php',
            fileManagerJson: './resource/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function(){this.sync();}
        });
    });

    // 图文选择
    $("#image").change(function(){
        $("#textfield").val($(this).val());
    });
    //提交表单
    $("#submitBtn").click(function(){
        if ($("#ticket_form").valid()) {
            $("#ticket_form").submit();
        }else{
            $('html,body').animate({scrollTop: $('label.error:visible:eq(0)').offset().top - 50}, 300);
        }

    });
    //关闭规格
    $("#close_spec").click(function(){
        $("#spec_type").hide();
        $("#spec_info").hide();
        $("[name='open_spec']").val(0);
    });
    //开启规格
    $('#open_spec').click(function(){
        $("#spec_type").show();
        $("#spec_info").show();
        $("[name='open_spec']").val(1);
    });
    //表单校验
    $("#ticket_form").validate({
        errorPlacement: function(error, element){
            if (element.attr('type') === 'file') {
                error.appendTo(element.parent().parent().parent().prev().find('td:first'));
            } else {
                error.appendTo(element.parent().parent().prev().find('td:first'));
            }
        },
        rules: {
            merchant_id: 'required',
            all_spec_name: {
                required: true,
                minlength: 3,
                maxlength: 200
            },
            all_label: {
                required: true,
                minlength: 3,
                maxlength: 255
            },
            cate1: 'required',
            /*cate2: 'required',*/
            <?php if($output['admin_info']['merchant_id']==0): ?>
            all_market_price: {
                required: true,
                number: true,
                min: 0.01,
                max: 9999999
            },
            market_price: {
                required: true,
                number: true,
                min: 0.01,
                max: 9999999
            },
            <?php endif; ?>
            cost_price_:{
                required: true,
                number: true,
                min: 0.01,
                max: 9999999
            },

            province_id: 'required',
            city_id: 'required',
            area_id: 'required',
            addr: 'required',
            /*thumb: 'required',*/
            face: 'required',
            content: 'required',
            content1: 'required',
           /* <?php foreach ($output['types'] as $type): ?>
            "types[<?php echo $type['type_id'];?>]":'required',
            store<?php echo $type['type_id']; ?>: {
                required: function () {
                    return true;
                },
                digits: true,
                min: 0,
                max: 9999999999
            },*/
          /*  <?php if($output['admin_info']['merchant_id']==0): ?>
            price<?php echo $type['type_id']; ?>: {
                required: function () {
                    return true;
                },
                number: true,
                min: 0.01,
                max: 9999999
            },
            cost_price<?php echo $type['type_id']; ?>: {
                required: function () {
                    return true;
                },
                number: true,
                min: 0.01,
                max: 9999999
            },
            <?php endif; ?>
            <?php endforeach; ?>*/
        },
        messages : {
            merchant_id: '<?php echo $lang['ticket_add_merchant_null']; ?>',
            all_spec_name: '<?php echo $lang['ticket_add_title_notice']; ?>',
            all_label: '标签不能为空',
            cate1: '<?php echo $lang['ticket_add_cate1_null']; ?>',
            cate2: '<?php echo $lang['ticket_add_cate2_null']; ?>',
            <?php foreach ($output['types'] as $type): ?>
           /* "types[<?php echo $type['type_id'];?>]":'<?php echo '请设置'.$type['type_name'].'库存和价格'; ?>',*/
            store<?php echo $type['type_id']; ?>: '<?php echo $lang['ticket_add_store_notice']; ?>',
            <?php if($output['admin_info']['merchant_id']==0): ?>
            price<?php echo $type['type_id']; ?>: '<?php echo $lang['ticket_add_price_notice']; ?>',
            cost_price<?php echo $type['type_id']; ?>: '协议价不能为空',
            <?php endif; ?>
            <?php endforeach; ?>
            <?php if($output['admin_info']['merchant_id']==0): ?>
            all_market_price: '展示价格不能为空',
            market_price: '<?php echo $lang['ticket_add_price_notice']; ?>',
            cost_price_:'协议不能为空',
            <?php endif; ?>
            province_id: '<?php echo $lang['ticket_add_province_null']; ?>',
            city_id: '<?php echo $lang['ticket_add_city_null']; ?>',
            area_id: '<?php echo $lang['ticket_add_area_null']; ?>',
            addr: '<?php echo $lang['ticket_add_addr_null']; ?>',
            thumb: '<?php echo $lang['ticket_add_image_null']; ?>',
            face: '<?php echo $lang['ticket_add_image_null']; ?>',
            content: '<?php echo $lang['ticket_add_detail_null']; ?>',
            content1: '<?php echo $lang['ticket_add_tips_null']; ?>'
        }
    });
</script>
<script type="text/javascript" src="./resource/css/diyUpload/js/webuploader.html5only.min.js"></script>
<script src="./resource/css/diyUpload/js/demo.js"></script>

